<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="信息描述">
        <el-tag type="info">excel模板说明</el-tag>
        <el-tag>
          <i class="el-icon-download"></i>
          <a :href="defaultExcelPath">点击下载模板</a>
        </el-tag>
      </el-form-item>
      <el-form-item label="选择excel">
        <el-upload
          ref="upload"
          :auto-upload="false"
          :on-exceed="fileUploadExceed"
          :on-success="fileUploadSuccess"
          :on-error="fileUploadFail"
          :limit="1"
          action="http://localhost:8081/admin/edu/subject/import"
          name="file"
          accept="application/vnd.ms-excel"
        >
          <el-button slot="trigger" size="small" type="primary">选中文件</el-button>
          <el-button :disabled="button" style="margin-left:10px" size="small" type="success" @click="uploadFile">服务器上传 </el-button>
        </el-upload>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { OSS_PATH } from "@/path/index.js";
export default {
  data() {
    return {
      defaultExcelPath: OSS_PATH + "课程分类列表模板.xls",
      button:false,
    };
  },
  methods: {
    test() {
      console.log(this.defaultExcelPath);
    },
    fileUploadExceed(){
        this.$message.error("超出限制")
    },
    fileUploadSuccess(){
        this.$message.success("文件上传成功");
        this.$refs.upload.clearFiles();
        this.button=false;
    },
    fileUploadFail(){
        this.$message.error("文件上传失败");
         this.$refs.upload.clearFiles();
        this.button=false;
    },
    uploadFile(){
        this.button=true;
        this.$refs.upload.submit();
    }
  },
};
</script>